package com.heima.tlias.dao;

import com.heima.tlias.pojo.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DeptMapper {
    //查询结果集映射
    //@Results({
    //        @Result(column = "update_time",property = "updateTime"),
    //        @Result(column = "create_time",property = "createTime")
    //})
    //给字段取别名
    //@Select("select id,name, update_time as updateTime ,create_time as createTime  from dept")
    @Select("select *  from dept")
    public List<Dept> queryList();

    /**
     * 根据部门id删除部门
     *
     * @param id 需要被删除的部门id
     */
    @Delete("delete from dept where id = #{id}")
    public void deleteById(Integer id);

    /**
     * 新增部门
     *
     * @param dept
     */
    @Insert("insert into dept values (null,#{name},#{updateTime},#{createTime})")
    public void insert(Dept dept);

    /**
     * 根据id查询数据详情
     *
     * @param id
     * @return
     */
    @Select("select * from dept where id = #{id}")
    public Dept queryById(Integer id);

    /**
     * 根据id更新数据
     *
     * @param dept
     */
    @Update("update dept set name = #{name},update_time = #{updateTime} where id = #{id}")
    public void updateById(Dept dept);
}
